package com.alibaba.algo.apiimpl.user;

import com.alibaba.algo.cooperation.common.BaseResult;
import com.alibaba.algo.cooperation.usercomponent.service.user.SysAppService;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SelectAppByUserReqVO;
import com.alibaba.algo.domain.user.SysAppDomain;
import com.alibaba.algo.domain.user.SysUserAppDomain;
import com.alibaba.algo.entity.user.SysApp;
import com.alibaba.algo.entity.user.SysUserApp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@RestController
public class SysAppServiceImpl implements SysAppService {

    @Autowired
    private SysAppDomain sysAppDomain;

    @Autowired
    private SysUserAppDomain sysUserAppDomain;


    /**
     * 查询全量租户列表
     *
     * @return 角色列表
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true, rollbackFor = Exception.class)
    public BaseResult selectList() {
        SysApp sysApp = new SysApp();
        //sysApp.setOrgId(sysOrgDelRequestVO.getOrgId());
        //List<SysApp> sysAppList = sysAppDomain.listByPara(sysApp, null);
        List<SysApp> sysAppList = sysAppDomain.listByPara(sysApp, null);
        return BaseResult.buildSuccess(sysAppList);
    }

    /**
     * 查询用户id对应租户列表
     * @param vo
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true, rollbackFor = Exception.class)
    public BaseResult selectAppByUserId(SelectAppByUserReqVO vo) {
        SysUserApp sysUserApp = new SysUserApp();
        sysUserApp.setUserId(vo.getUserId());
        log.info("SysAppService selectAppByUserId param:{}",sysUserApp);
        List<SysUserApp> sysAppList = sysUserAppDomain.listByPara(sysUserApp, null);
        return BaseResult.buildSuccess(sysAppList);
    }
}
